package com.design.proxy.hello;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * 
 * jdk动态代理实例
 *
 */
public class HelloProxy {

	public static void main(String[] args) {
		IHello hello = (IHello) Proxy.newProxyInstance(HelloProxy.class.getClassLoader(),
				new Class<?>[] { IHello.class }, new InvocationHandler() {
					@Override
					public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
						return "Hello " + args[0];
					}
				});

		String r = hello.hello("world");

		System.out.println(r);
	}

}
